<?php

namespace Common\Model;

use Think\Model;

class UrlModel extends Model
{
    protected $_validate = array(
        array('alias', 'require', '调用名必须填写！', 1),
        array('locator', 'require', '替换规则必须填写！', 1),
        array('rule_key', 'require', '路由规则必须填写！', 1),
        array('rule_var', 'require', '对应方法必须填写！', 1),
    );

    /**
     * 获取列表
     *
     * @param string $map
     * @param bool $page
     * @param string $sort
     * @param string $num
     * @return mixed
     */
    public function get_list($map = '', $page = false, $sort = '', $num = '')
    {
        $limit = $num ? $num : 10;
        if ($page) {
            $count = $this->where($map)->count();
            $Page = pager($count, $limit);
            $limit = $Page->firstRow . ',' . $Page->listRows;
            $page_str = $Page->fshow();
        }
        $result = $this->where($map)->order($sort)->limit($limit)->select();
        foreach ($result as $key => $v) {
            $list[] = $v;
        }
        $return['list'] = $list;
        if ($page) {
            $return['count'] = $count;
        } else {
            $return['count'] = count($list);
        }
        $return['page'] = $page_str;
        return $return;
    }
}